测试链接：https://leetcode.cn/problems/M1oyTv/description/
class Solution {
public:
    string minWindow(string s, string t) {
        if (s.empty() || t.empty())
            return "";

        int n = s.size();
        int m = t.size();
        unordered_map<int, int> hash1;
        for (auto& e : t) {
            hash1[e - 'a']++;
        }

        string ans;
        unordered_map<int, int> hash2;
        int minlen = INT_MAX;
        for (int l = 0, r = 0; r < n; r++) {
            char in = s[r] - 'a';
            hash2[in]++;

            while (check(hash1, hash2)) {
                int curlen = r - l + 1;
                if(curlen < minlen)
                {
                    minlen = curlen;
                    ans = s.substr(l, curlen);
                }
                // minlen = min(minlen, r - l + 1);
                // ans = s.substr(l, minlen);换成这个会错
                char out = s[l] - 'a';
                hash2[out]--;
                l++;
            }
        }
        return minlen == INT_MAX ? "" : ans;
    }

    bool check(unordered_map<int, int>& hash1, unordered_map<int, int>& hash2)
    {
        for(auto &pair : hash1)
        {
            int key = pair.first;
            int require = pair.second;
            auto it2 = hash2.find(key);

                if(hash2[key] < require)
                {
                    return false;
                }
        }
        return true;
    }
};